<template>
  <div class="hello">
    <h1>{{ msg }}</h1>
    <hr />
    <div @click="changeMessage">message: {{ message }}</div>
  </div>
</template>

<script>
import {
  onBeforeMount,
  onBeforeUnmount,
  onBeforeUpdate,
  onMounted,
  onUnmounted,
  onUpdated,
  ref,
} from "vue";
export default {
  name: "HelloWorld",
  props: {
    msg: String,
  },
  setup() {
    console.log("setUp");
    const message = ref("我爱你");
    const changeMessage = () => {
      message.value = "你不配";
    };

    onBeforeMount(() => {
      console.log("onBeforeMount 挂载前");
    });

    onMounted(() => {
      console.log("onMounted 挂载后");
    });

    onBeforeUpdate(() => {
      console.log("onBeforeUpdate DOM更新前");
    });

    onUpdated(() => {
      console.log("onUpdated DOM更新后");
    });

    // 当前组件卸载得时候会执行
    // 1. v-if 是false得时候可以引起组件得卸载
    // 2. 整个app应用卸载的时候,也会引起组件的卸载
    onBeforeUnmount(() => {
      console.log("onBeforeUnmount 卸载前");
    });

    onUnmounted(() => {
      console.log("onUnmounted 卸载后");
    });

    return {
      message,
      changeMessage,
    };
  },
};
</script>

<style scoped>
</style>
